package emulator.unittest.hardware.memory;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.memory.MemoryBlock;

public class MemoryBlockTest {

	private static int memory_block_size = 4096;
	private MemoryBlock memory;

	@Before
	public void setUp() throws Exception {
		memory = new MemoryBlock(memory_block_size);
	}

	@Test
	public void testInitialAllZero() throws EmulatorException
	{
		for (int i = 0; i < memory_block_size; i++)
			assertEquals(0, memory.read(i));
	}
	
	@Test
	public void testReadWrite() throws EmulatorException
	{
		memory.write(0, 0x55);
		memory.write(1, 0xAA);
		memory.write(memory_block_size-1, 0xFF);
		assertEquals(0x55, memory.read(0));
		assertEquals(0xAA, memory.read(1));
		assertEquals(0x00, memory.read(2));
		assertEquals(0x00, memory.read(memory_block_size-2));
		assertEquals(0xFF, memory.read(memory_block_size-1));
	}
}
